package com.lovo.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.bean.SysOrder;
import com.lovo.service.ISysOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * ????? 前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-09-17
 */
@RestController
@RequestMapping("qd/order")
public class SysOrderController {

    @Autowired
    public ISysOrderService sysOrderService;


    @GetMapping("findAllOrderByUserId/{pageNO}/{userId}")
    public IPage<SysOrder> findAllOrderByUserId(@PathVariable("pageNO") Integer pageNO, @PathVariable("userId") Integer userId) {
        return sysOrderService.findAllOrderByUserId(pageNO, userId);
    }

    @GetMapping("buyCar/{userId}/{addressId}/{buyType}")
    public String buyCar(@PathVariable("userId") Integer userId,
                         @PathVariable("addressId") Integer addressId,
                         @PathVariable("buyType") String buyType) {

        boolean a = sysOrderService.buyCar(userId, addressId, buyType);
        if (a) {
            return "ok";
        }
        return "no";
    }

    @GetMapping("addOrder/{userId}/{addressId}/{buyType}/{productId}/{num}")
    public String addOrder(@PathVariable("userId") Integer userId,
                           @PathVariable("addressId") Integer addressId,
                           @PathVariable("buyType") String buyType,
                           @PathVariable("productId") Integer productId,
                           @PathVariable("num") Integer num) {

        boolean a = sysOrderService.addOrder(userId, addressId, buyType, productId, num);
        if (a) {
            return "ok";
        }
        return "no";

    }


}
